local zenning = fk.CreateSkill{
    name = "ym_water__zenning",
}
Fk:loadTranslationTable{
    ["ym_water__zenning"] = "谮咛",
    [":ym_water__zenning"] = "当其他角色使用【杀】或【决斗】时，你可将一张牌加入对应的实体牌，然后重新指定合法目标；若如此做，其可用一张异色的基本牌替换你加入的牌，然后复原目标。",
    ["#ym_water__zenning"] = "谮咛：是否将一张牌加入 %dest使用的 %arg的底牌，然后重新指定合法目标",
    ["#ym_water__zenning2"] = "谮咛：是否用一张异色基本牌替换底牌中的 %arg，然后复原此牌目标",
}

zenning:addEffect(fk.AfterCardTargetDeclared,{
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(zenning.name) and table.contains({"slash","duel"},data.card.trueName) and target ~= player
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local tos ,cards, bool = room:askToChooseCardsAndPlayers(player,{
            max_card_num = 1,
            min_card_num = 1,
            no_indicate = true,
            max_num = 1,
            min_num = 1,
            targets = data:getExtraTargets({bypass_times = true}),
            cancelable = true,
            pattern = ".",
            skill_name = zenning.name,
            prompt = "#ym_water__zenning::"..data.from.id..":::"..data.card:toLogString(),
        })
        if bool then
            event:setCostData(self,{tos = tos , cards = cards})
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local cards = event:getCostData(self).cards
        local tos = event:getCostData(self).tos
        data.extra_data = data.extra_data or {}
        data.extra_data.ym_water__zenning = data.extra_data.ym_water__zenning or {}
        table.insertIfNeed(data.extra_data.ym_water__zenning, cards[1])
        room:moveCardTo(cards[1], Card.Processing, nil, fk.ReasonJustMove, zenning.name, nil, true)
        data.card:addSubcard(cards[1])

        local color = "heart,diamond"
        if Fk:getCardById(cards[1]).color == Card.Red then
            color = "spade,club"
        end
        local cs = room:askToCards(data.from,{
            max_num = 1,
            min_num = 1,
            pattern = ".|.|"..color.."|.|.|basic",
            skill_name = zenning.name,
            prompt = "#ym_water__zenning2:::"..Fk:getCardById(cards[1]):toLogString(),
        })

        if #cs > 0 then
            table.removeOne(data.extra_data.ym_water__zenning, cards[1])
            table.insertIfNeed(data.extra_data.ym_water__zenning, cs[1])
            table.removeOne(data.card.subcards, cards[1])
            room:moveCardTo(cs[1], Card.Processing, nil, fk.ReasonJustMove, zenning.name, nil, true)
            data.card:addSubcard(cs[1])
            room:obtainCard(data.from, cards[1], true, fk.ReasonJustMove, data.from)
        else
            local targets = data.tos
            data:removeTarget(targets)
            data:addTarget(tos)
        end
    end,
})

zenning:addEffect(fk.CardUseFinished,{
    can_refresh = function (self, event, target, player, data)
        return data.extra_data and data.extra_data.ym_water__zenning
    end,
    on_refresh = function (self, event, target, player, data)
        player.room:cleanProcessingArea(data.extra_data.ym_water__zenning)
    end,
})

return zenning